package top.arryweb.application.common.constant;

import lombok.AllArgsConstructor;

import java.util.Arrays;
import top.arryweb.application.common.exception.BusinessRuntimeException;

/**
 * @author xiong04
 * @since 2021-05-02
 */
@AllArgsConstructor
public enum  PayStatus {
	TO_BE_PAID(1,"待支付状态","toBePaid"),
	SUCCEED(2,"支付成功","succeed"),
	PARTIAL_REFUND(3,"部分退款","partialRefund"),
	REFUNDED(4,"已退款","refunded"),
	FAIL(5,"支付失败","fail"),
	REVOKED(6,"已撤销","revoked");



	private final int rank;

	private final String comments;

	private final String name;

	public int getRank() {
		return rank;
	}

	public String getComments() {
		return comments;
	}

	public String getName() {
		return name;
	}

	public static PayStatus setRank(int rank){
		return Arrays.stream(PayStatus.values()).filter(payStatus -> payStatus.getRank() == rank).findFirst()
				.orElseThrow(() -> new BusinessRuntimeException("无此订单状态"));
	}

	public static boolean judgeUpdateOrderStatus(PayStatus payStatus,PayStatus orderStatus){
		boolean contains = ConstantEnumHandler.UPDATE_ORDER_STATUS_MAP.get(payStatus).contains(orderStatus);
		if (!contains){
			throw new BusinessRuntimeException("状态修改失败");
		}
		return contains;
	}


}
